﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <link href="~/X-admin/lib/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/theme123.min.css" rel="stylesheet" />
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .uploadbg {
               padding: 0px 20px;
        }
        .uploadMsg {
                 background: #fff;
                 min-height: 513px;
                 padding: 0px 20px;
        }
        .p_title{
                text-align: center;
            padding: 10px;
            font-size: 18px;
        }
        .mar10 {
            margin-top:10px;
        }
        .pad20 {
            padding:20px 5px;
        }
        .pad10 {
               line-height: 40px;
        }
        .clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden}
.clearfix{*+height:1%;}
        /*.uploadImg {
            font-size: 46px;
    font-family: auto;
    width: 100px;
    height: 100px;
    background: #01AAED;
    color: #eee;
    font-weight: bold;
    text-align: center;
    line-height: 100px;
    cursor:pointer;
        }*/
        .fl {
            float:left;
        }
        .uploadbg .filea {
            padding: 5px 20px;
            color: #2d2dec;
            font-size: 14px;
        }
        .filea a {
            color:#1c51ef;
        }
    </style>
</head>
<body style="background:#fff;">
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="#">首页</a>
            @*<a href="">演示</a>*@
            <a>
                <cite>资料上传</cite>
            </a>
        </span>
    </div>
    <div class="uploadbg">
        <div class="uploadMsg"  id="fileboox">
            <div class="layui-row">
                <div class="layui-col-md12 p_title" id="projectName">@ViewBag.project</div>
                <div class="layui-hide" id="admingId">@ViewBag.id</div>
            </div>
            <div class="electri mar10" >
                <div class="layui-row layui-bg-gray pad10">
                    <div class="layui-col-md10 ">1.电气</div>
                    <div class="layui-col-md2 ">
                    <button type="button" class="layui-btn" id="electrics" x_title="电气" x_name="@ViewBag.project" x-id="@ViewBag.id">
                            <i class="layui-icon">&#xe67c;</i>上传
                        </button>
                    </div>
                </div>
                <div class="electri_item pad20 clearfix" id="electri">
                 
                </div>
            </div>
            <div class="management mar10"  >
                <div class="layui-row layui-bg-gray">
                    <div class="layui-col-md10 layui-bg-gray pad10">2.管理</div>
                    <div class="layui-col-md2 ">
                        <button type="button" class="layui-btn" id="manages" x_title="管理" x_name="@ViewBag.project" x-id="@ViewBag.id">
                            <i class="layui-icon">&#xe67c;</i>上传
                        </button>
                    </div>
                </div>
                <div class="manage_item pad20 clearfix" id="manage">

                </div>
            </div>
           <div class="machine mar10"  >
               <div class="layui-row layui-bg-gray">
                   <div class="layui-col-md10 layui-bg-gray pad10">3.机械</div>
                   <div class="layui-col-md2 ">
                       <button type="button" class="layui-btn" id="machines" x_title="机械" x_name="@ViewBag.project" x-id="@ViewBag.id">
                           <i class="layui-icon">&#xe67c;</i>上传
                       </button>
                   </div>
               </div>
               <div class="machine_item pad20 clearfix" id="machine">

               </div>
           </div>
           <div class="software mar10" >
               <div class="layui-row layui-bg-gray">
                   <div class="layui-col-md10 layui-bg-gray pad10">4.软件</div>
                   <div class="layui-col-md2 ">
                       <button type="button" class="layui-btn" id="softwares" x_title="软件" x_name="@ViewBag.project" x-id="@ViewBag.id">
                           <i class="layui-icon">&#xe67c;</i>上传
                       </button>
                   </div>
               </div>
               <div class="software_item pad20 clearfix" id="software">

               </div>
           </div>
            <div class="demand mar10" >
                <div class="layui-row layui-bg-gray">
                    <div class="layui-col-md10 layui-bg-gray pad10">5.需求</div>
                    <div class="layui-col-md2 ">
                        <button type="button" class="layui-btn" id="demands" x_title="需求" x_name="@ViewBag.project" x-id="@ViewBag.id">
                            <i class="layui-icon">&#xe67c;</i>上传
                        </button>
                    </div>
                </div>
                <div class="demand_item pad20 clearfix" id="demand">

                </div>
            </div>
           
        </div>
    </div>
   
<script>
    layui.use(['laydate', 'form', 'upload', 'jquery', 'laypage'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        var upload = layui.upload;
        var $ = layui.jquery;
        var laypage = layui.laypage;

        var search = $("iframe").context.location.search;  //拿到参数
        var coisd = search.split('&')[1].split("=")[1];
      
      
        uploadFile("#demands");  //上传需求
        uploadFile("#manages");  //上传管理
        uploadFile("#electrics");  //上传电气
        uploadFile("#machines");  //上传机械图纸
        uploadFile("#softwares");  //上传软件
        function uploadFile(id) {
           upload.render({
                elem: id //绑定元素
           , url: '/Upload/Upload' //上传接口
            , accept: 'file'
             , before: function (obj) {
                 $.extend(true, this.data, {
                     name: $(this.elem).attr('x_title'),
                     projectName: $(this.elem).attr('x_name'),
                     id: $(this.elem).attr('x-id')
                 });
             }
           , done: function (res) {
               //上传完毕回调
               console.log(res)
               if (res.Success) {
                   layer.msg('上传成功', { icon: 6 }, function () {
                  
                       if (id == "#electrics") {
                           getFilelist('/Home/getElectricList', coisd, '#electri');
                       }
                       if (id == "#demands") {
                           getFilelist('/Home/getRemandList', coisd, '#demand');
                       }
                       if (id == "#manages") {
                           getFilelist('/Home/getManagementList', coisd, '#manage');
                       }
                       if (id == "#machines") {
                           getFilelist('/Home/getMachineList', coisd, '#machine');
                       }
                       if (id == "#softwares") {
                           getFilelist('/Home/getSoftwareList', coisd, '#software');
                       }
                   });
               
               }

           }
           , error: function () {
               //请求异常回调
               layer.msg("请求异常", {icon:5})
           }
            });
        }


        //查看
        $("#renderList").on('click', '.showMsg', function () {
            var id = $(this).attr('data-id');
          
            parent.xadmin.add_tab('资料上传', '/Login/Index');
        })
        //删除文件
        $("#fileboox").on('click', 'a.removeIcon', function () {
            var path = $(this).parent('div.filea').find('a').attr('href');
            var name = $(this).parent('div.filea').find('a').attr('data-name');
            var id = $(this).parent('div.filea').find('a').attr('data-id');

            layer.confirm('是否确认删除？', { icon: 3, title: '提示' }, function (layerIndex) {
                $.post('/Home/DeleteDirectory', { path: path,name:name ,id:id}, function (res) {
                    var data = JSON.parse(res);
                 
                    if (data.success) {
                        layer.msg(data.msg, { icon: 6 }, function () {
                            layer.close(layerIndex);
                            if (name == "电气") {
                                getFilelist('/Home/getElectricList', coisd, '#electri');
                            }
                            if (name == "需求") {
                                getFilelist('/Home/getRemandList', coisd, '#demand');
                            }
                            if (name == "管理") {
                                getFilelist('/Home/getManagementList', coisd, '#manage');
                            }
                            if (name == "机械") {
                                getFilelist('/Home/getMachineList', coisd, '#machine');
                            }
                            if (name == "软件") {
                                getFilelist('/Home/getSoftwareList', coisd, '#software');
                            }
                        })
                    } else {
                        layer.msg(data.msg, { icon: 5 })
                    }
                })
            })
        })
        //执行一个laydate实例
        laydate.render({
            elem: '#start', //指定元素
            trigger:'click'
        });
        $(function () {
         
            getFilelist('/Home/getElectricList', coisd, '#electri');//加载电气文件
            getFilelist('/Home/getManagementList', coisd, '#manage');//加载管理文件
            getFilelist('/Home/getMachineList', coisd, '#machine');//加载机械文件
            getFilelist('/Home/getSoftwareList', coisd, '#software');//加载软件文件
            getFilelist('/Home/getRemandList', coisd, '#demand');//加载需求文件
        })
        //查询
        function getFilelist(url, id, selector) {
            var str = "";
            $.post(url, { id: id }, function (res) {
                var data = JSON.parse(res.data);
                if (data.length != 0) {
                    $.each(data, function (index, item) {
                        str += '<div class="filea fl"><a href="' + item.url + '" target="_blank" data-name="' + item.name + '" data-id="'+item.id+'">' + item.filename + '</a>' +
                                    '<a href="javascript:;" class="removeIcon"><img src="/Content/img/delete.png" style="width: 20px;padding: 0px 6px;"/></a>' +
                        '</div>';
                    })
                    $(selector).html(str);
                } else {
                    $(selector).html('<a href="javascript"void();">暂无文件</a>');
                }
               
            })
        }

        //文件路径提交
        $("#add").on('click', function () {
            layer.open({
                type: 1,
                title: "资料上传",
                content: $("#showMsg"),
                area: ['700px', '450px'],
                success: function () {
                    form.on('submit(formDemo)', function (data) {
                        var obj = {
                            demandurl: data.field.demandurl,
                            demand: data.field.demand,
                            electricurl: data.field.electricurl,
                            electric: data.field.electric,
                            machineurl: data.field.machineurl,
                            machine:data.field.machine,
                            managementurl: data.field.managementurl,
                            management: data.field.management,
                            softwareurl: data.field.softwareurl,
                            software: data.field.software,
                            project: data.field.project,

                        }
                        console.log(obj)
                        var layerIndex;
                        $.ajax({
                            type: 'POST',
                            url: "/Home/Create",
                            beforeSend: function () {
                                layerIndex = layer.load();
                            },
                            data: {
                                demandurl: data.field.demandurl,
                                demand: data.field.demand,
                                electricurl: data.field.electricurl,
                                electric: data.field.electric,
                                machineurl: data.field.machineurl,
                                machine:data.field.machine,
                                managementurl: data.field.managementurl,
                                management: data.field.management,
                                softwareurl: data.field.softwareurl,
                                software: data.field.software,
                                project: data.field.project,
                            },
                            success: function (res) {
                                if (res.Success) {
                                    layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                        layer.closeAll();
                                        list.init(1, 10);
                                        list.render(function (total) {
                                            list.page(total);
                                        });
                                    });
                                } else {
                                    layer.msg(res.msg, { icon: 5, time: 1000 }, function () {
                                        layer.closeAll();
                                    });
                                }
                            },
                            error: function (e) {
                                layer.msg(e, {icon:5})
                            },
                            complete: function () {

                            }
                        })
                        return false;
                    })
                },
                end: function (index, layero) {
                    $(".showMsg a.showFile", layero).remove();
                },

            })
        })
      });


       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要停用吗？',function(index){

              if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

              }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
              }

          });
      }

      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              $(obj).parents("tr").remove();
              layer.msg('已删除!',{icon:1,time:1000});
          });
      }



      function delAll (argument) {
        var ids = [];

        // 获取选中的id
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });

        layer.confirm('确认要删除吗？'+ids.toString(),function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>
</body>
</html>